<template>
  <div>
    <h2 class="title">动火方案审批表</h2>
    <table>
      <tr>
        <td colspan="1">
          附件:
        </td>
        <td colspan="4">
          <wise-file v-model="obj.fileUrl" upload-type="file" accept=".doc,.pdf" :limit="6" />
        </td>
      </tr>
      <tr>
        <td>编号:</td>
        <td>
          <el-input v-model="obj.serialNumber" placeholder="请输入" />
        </td>
        <td>方案名称:</td>
        <td colspan="2">
          <el-input v-model="obj.name" placeholder="请输入" />
        </td>
      </tr>
      <tr>
        <td rowspan="5">一、施工组织</td>
        <td colspan="1">动火申请单位:</td>
        <td colspan="3">
          <el-input v-model="obj.hotApplyUnit" placeholder="请输入" />
        </td>
      </tr>

      <tr>
        <td colspan="1">动火作业时间:</td>
        <td colspan="3">
          <el-date-picker
v-model="value1"
type="datetimerange" value-format="timestamp" range-separator="至"
                          start-placeholder="开始日期"
end-placeholder="结束日期" @change="timeChange"
/>
        </td>
      </tr>
      <tr>
        <td>基层战场(作业区)负责人:</td>
        <td>
          <el-input v-model="obj.workAdminUserName" placeholder="请输入" />
        </td>
        <td>动火作业级别:</td>
        <td>
          <el-input v-model="obj.hotLevel" placeholder="请输入" />
        </td>
      </tr>
      <tr>
        <td colspan="1">动火作业地点:</td>
        <td colspan="3">
          <el-input v-model="obj.hotPlace" placeholder="请输入" />
        </td>
      </tr>
      <tr>
        <td>动火作业单位负责人:</td>
        <td>
          <el-input v-model="obj.hotWorkUnitAdmin" placeholder="请输入" />
        </td>
        <td>动火作业单位监护人:</td>
        <td>
          <el-input v-model="obj.hotWorkUnitGuardian" placeholder="请输入" />
        </td>
      </tr>
      <tr>
        <td colspan="1">二、动火作业内容及目的</td>
        <td colspan="4">
          <el-input v-model="obj.hotContent" type="textarea"> placeholder="请输入"</el-input>
        </td>
      </tr>
      <tr>
        <td colspan="5">三、动火作业部位与周围油气流程及置换隔断示意图（管线要注明介质、尺寸，控制流程中的阀门要编号，由动火申请单位绘制，生产部门审核）

          <div>
            <wise-file v-model="obj.sketchMap" upload-type="image" :limit="6" />
          </div>
          <p class="textRight"> 绘制：
            <el-input v-model="obj.drawUser" class="label_put" type="input" placeholder="请输入" />
          </p>
          <p class="textRight"> 审核：
            <el-input v-model="obj.processUser" class="label_put" type="input" placeholder="请输入" />
          </p>
          <p class="textCenter">（特级、一级由生产科工艺设备管理人员审核，二级由作业区工艺技术员审核）</p>
        </td>
      </tr>
      <tr>
        <td colspan="5">四、动火作业安全技术措施及现场施工组织（内容较多时可另加纸）（内容参见附录C.1）
          <el-input v-model="obj.measure" type="textarea" placeholder="请输入" />
        </td>
      </tr>
      <tr>
        <td colspan="5">五、动火作业单位审查意见（负责人）
          <div class="min-height100" />
          <div class="desc">
            <p>签字:
              <el-select v-model="obj.hotWorkUnitAdminUserId" placeholder="请选择" @change="changeHotWorkUnitAdminUserId">
                <el-option
v-for="item in options"
:key="item.userId" :disabled="item.disabled" :label="item.username"
                           :value="item.userId"
/>
              </el-select>
            </p>
          </div>
        </td>
      </tr>
      <tr>
        <td colspan="5">六、作业区域所在基层单位审查意见：
          <div class="min-height100" />
          <div class="desc">
            <p>签字:
              <el-select v-model="obj.basicUnitAdminUserId" placeholder="请选择" @change="changeBasicUnitAdminUserId">
                <el-option
v-for="item in options"
:key="item.userId" :disabled="item.disabled" :label="item.username"
                           :value="item.userId"
/>
              </el-select>
            </p>

          </div>
        </td>
      </tr>
      <tr>
        <td colspan="1">七、二级单位业务主管部门审查意见</td>
        <td colspan="1">生产调度运行部门：
          <div class="min-height60" />
          <p>签字:

            <el-select
v-model="obj.twoProductionAdminUserId"
placeholder="请选择"
                       @change="changeTwoProductionAdminUserId"
>
              <el-option
v-for="item in options"
:key="item.userId" :disabled="item.disabled" :label="item.username"
                         :value="item.userId"
/>
            </el-select>
          </p>
        </td>
        <td colspan="2">资产设施管理部门（生产、管道或工程）：
          <div class="min-height60" />
          <p>签字:
            <el-select v-model="obj.towAssetsAdminUserId" placeholder="请选择" @change="changeTowAssetsAdminUserId">
              <el-option
v-for="item in options"
:key="item.userId" :disabled="item.disabled" :label="item.username"
                         :value="item.userId"
/>
            </el-select>
          </p>
        </td>
        <td colspan="1">安全监管部门：
          <div class="min-height60" />
          <p>签字:
            <el-select v-model="obj.twoSafetyAdminUserId" placeholder="请选择" @change="changeTwoSafetyAdminUserId">
              <el-option
v-for="item in options"
:key="item.userId" :disabled="item.disabled" :label="item.username"
                         :value="item.userId"
/>
            </el-select>
          </p>
        </td>
      </tr>
      <tr>
        <td colspan="5">八、二级单位主管领导：
          <div class="min-height100" />
          <div class="desc">
            <p>签字:
              <el-select v-model="obj.leaderAdminUserId" placeholder="请选择" @change="changeLeaderAdminUserId">
                <el-option v-for="item in options1" :key="item.userId" :label="item.username" :value="item.userId" />
              </el-select>
            </p>
          </div>
        </td>
      </tr>
    </table>
    <div class="botDesc">
      <p>保存单位：动火单位</p>
      <p>保存期限：一年</p>
    </div>
    <div />
    <span slot="footer" class="dialog-footer">
      <el-row type="flex" justify="end">
        <el-button type="primary" @click="submitHandle">确认</el-button>
        <el-button>重置</el-button>
      </el-row>
    </span>

  </div>
</template>

<script>
import {
  postHandle
} from '@/api'
import WiseFile from '@/components/Crud/components/wiseFile'
export default {
  components: {
    WiseFile
  },
  props: ['object', 'id'],
  data() {
    return {
      obj: {},
      dialogVisible: false,
      userList: '/api/v1/welder-uac-second/space-user-member-role-comb/get-user-info-by-roles',
      jituanList: '/api/v1/welder-sbtx-second/hot-approval-comb/list',
      editUrl: '/api/v1/welder-sbtx-second/hot-program-comb/update',
      show: '/api/v1/welder-sbtx-second/hot-program-comb/show/',
      options: '',
      options1: [],
      value: '',
      value1: [],
      isSubminBtn: false,
      obj1: {}
    }
  },
  computed: {
    spaceId() {
      return this.$store.getters.entSpaceId
    }
  },
  created() {
    
  },
  mounted() {
    this.getOptionsItems()
    this.getEntAdminData()
    this.getObjectById()
  },
  methods: {
    changeHotWorkUnitAdminUserId(val) {
      if (val != this.obj1.hotWorkUnitAdminUserId) {
        this.isSubminBtn = true
      }
    },
    changeBasicUnitAdminUserId(val) {
      if (val != this.obj1.basicUnitAdminUserId) {
        this.isSubminBtn = true
      }
    },
    changeTwoProductionAdminUserId(val) {
      if (val != this.obj1.twoProductionAdminUserId) {
        this.isSubminBtn = true
      }
    },
    changeTowAssetsAdminUserId(val) {
      if (val != this.obj1.towAssetsAdminUserId) {
        this.isSubminBtn = true
      }
    },
    changeTwoSafetyAdminUserId(val) {
      if (val != this.obj1.twoSafetyAdminUserId) {
        this.isSubminBtn = true
      }
    },
    changeLeaderAdminUserId(val) {
      if (val != this.obj1.leaderAdminUserId) {
        this.isSubminBtn = true
      }
    },
    getOptionsItems() {
      let params = {
        d: {
          c: [{
            'key': 'authToken',
            'value': this.$store.getters.token
          },
          {
            'key': 'entSpaceId',
            'value': this.$store.getters.entSpaceId
          }
          ]
        },
        'obj': {
          'roleCodes': ['formalEmployee'],
          'spaceId': this.spaceId,
          'spaceProperty': 1
        }
      }
      if (this.userList) {
        postHandle(this.userList, params).then(res => {
          this.options = res.result
        })
      }
    },
    getEntAdminData() {
      postHandle('/api/v1/welder-uac-second/space-user-member-role-comb/get-ent-admin/' + this.spaceId).then(res => {
        this.options1 = res.result
      })
    },
    getObjectById() {
      postHandle(this.show + this.id, {}).then((response) => {
        this.obj = response.result
        this.obj1 = JSON.parse(JSON.stringify(response.result))
        this.value1.push(this.obj.hotWorkStartTime, this.obj.hotWorkEndTime)
        if (this.options.findIndex(item => item.userId == this.obj.hotWorkUnitAdminUserId) === -1) {
          this.isSubminBtn = false
          this.options.push({
            userId: this.obj.hotWorkUnitAdminUserId,
            username: '用户不存在!',
            disabled: true
          })
        } else {
          this.isSubminBtn = true
        }
        if (this.options.findIndex(item => item.userId == this.obj.basicUnitAdminUserId) === -1) {
          this.isSubminBtn = false
          this.options.push({
            userId: this.obj.basicUnitAdminUserId,
            username: '用户不存在!',
            disabled: true
          })
        } else {
          this.isSubminBtn = true
        }
        if (this.options.findIndex(item => item.userId == this.obj.twoProductionAdminUserId) === -1) {
          this.isSubminBtn = false
          this.options.push({
            userId: this.obj.twoProductionAdminUserId,
            username: '用户不存在!',
            disabled: true
          })
        } else {
          this.isSubminBtn = true
        }
        if (this.options.findIndex(item => item.userId == this.obj.towAssetsAdminUserId) === -1) {
          this.isSubminBtn = false
          this.options.push({
            userId: this.obj.towAssetsAdminUserId,
            username: '用户不存在!',
            disabled: true
          })
        } else {
          this.isSubminBtn = true
        }
        if (this.options.findIndex(item => item.userId == this.obj.twoSafetyAdminUserId) === -1) {
          this.isSubminBtn = false
          this.options.push({
            userId: this.obj.twoSafetyAdminUserId,
            username: '用户不存在!',
            disabled: true
          })
        } else {
          this.isSubminBtn = true
        }
        if (this.options1.findIndex(item => item.userId == this.obj.leaderAdminUserId) === -1) {
          this.isSubminBtn = false
          this.options1.push({
            userId: this.obj.leaderAdminUserId,
            username: '用户不存在!',
            disabled: true
          })
        } else {
          this.isSubminBtn = true
        }
      })
    },
    submitHandle() {
      this.drawer = false
      if (this.isSubminBtn) {
        if (this.editUrl) {
          postHandle(this.editUrl + '/' + this.id, {
            obj: this.obj
          }).then(res => {
            if (res._rd) {
              this.$message({
                message: '创建成功',
                type: 'success'
              })
              this.$emit('hideDjog1', false)
            }
          })
        }
      } else {
        this.$message.error('用户不存在!请重新选择')
      }
    },
    timeChange(a) {
      this.obj.hotWorkStartTime = a[0]
      this.obj.hotWorkEndTime = a[1]
    }
  }
}
</script>

<style scoped lang="less">
  table {
    border-collapse: collapse;
    width: 100%;
    border: 1px solid #000;
    text-align: left;

    td {
      line-height: 22px;
      border: 1px solid;
      padding: 14px;
    }

    td:nth-child(odd) {
      width: 20%;
    }
  }

  .min-height100 {
    min-height: 100px
  }

  .min-height60 {
    min-height: 60px
  }

  .desc {
    text-align: right;
    width: 100%;

    p {
      width: 250px;
      text-align: left;
      display: inline-block;
    }
  }

  .botDesc {
    padding-top: 10px;
  }

  .botDesc p {
    line-height: 40px;
  }

  .textRight {
    text-align: right;
    line-height: 30px;
  }

  .textCenter {
    text-align: center;
  }

  .title {
    text-align: center;
    /* line-height: 40px; */
    padding-bottom: 20px;
  }

  .label_put {
    width: 30%
  }
</style>
